package com.ymatou.iapi.productmanager.testcase.old202012;

import com.ymatou.iapi.productmanager.parameter.AddMicroProductBean;
import com.ymatou.iapi.productmanager.parameter.MicroProductBean;
import com.ymatou.iapi.productmanager.parameter.WeChatCatalogDto;
import com.ymatou.iapi.productmanager.service.MicroProductCall;
import com.ymttest.business.service.AddProductCallServiceV2;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
import org.junit.*;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.ArrayList;
import java.util.List;

/**
*编辑微店商品
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
//业务下架
public class Ts_MicroProduct{
	private static MicroProductBean microproductBean;
	private static MicroProductCall microproductCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("编辑微店商品");
	}

	@Before
	public void caseUp() {
		microproductBean=new MicroProductBean();
		microproductCall=new MicroProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(microproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_001() {
		Logger.start(true,"编辑微店商品，商品属性");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setSecondCategoryId(1004);
			microproductBean.getProduct().setProductName("山沟" + YMTDateUtil.getDate());
			List<String> picUrls = new ArrayList<>();
			picUrls.add("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
			microproductBean.getProduct().setPicUrls(picUrls);
			microproductBean.getProduct().setCatalogStatus(2);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_002() {
		Logger.start(true,"编辑微店商品，规格属性");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getCatalogList().get(0).setCatalogName("bihaoa"+YMTDateUtil.getDate());
			microproductBean.getProduct().getCatalogList().get(0).setPrice(1000);
			microproductBean.getProduct().getCatalogList().get(0).setStock(100);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_003() {
		Logger.start(true,"编辑微店商品，文描属性");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getProductDescModel().setDescription("天下第一");
			List<String> picList = new ArrayList<>();
			picList.add("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
			microproductBean.getProduct().getProductDescModel().setDescPicList(picList);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_004() {
		Logger.start(true,"编辑微店商品，多规格变单规格");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getCatalogList().remove(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_005() {
		Logger.start(true,"编辑微店商品，单规格变多规格");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			microProductBean.getProduct().getCatalogList().remove(0);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);

			WeChatCatalogDto weChatCatalogDto1 = new WeChatCatalogDto();
			weChatCatalogDto1.setCatalogName("规格1"+YMTDateUtil.getDate());
			weChatCatalogDto1.setPicUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
			weChatCatalogDto1.setPrice(100);
			weChatCatalogDto1.setStock(10000);
			microproductBean.getProduct().getCatalogList().add(weChatCatalogDto1);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_006() {
		Logger.start(true,"参数校验-编辑微店商品，买手id为0,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setSellerId(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_007() {
		Logger.start(true,"参数校验-编辑微店商品，买手不存在,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setSellerId(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_008() {
		Logger.start(true,"参数校验-编辑微店商品，商品二级类目为0,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setSecondCategoryId(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_009() {
		Logger.start(true,"参数校验-编辑微店商品，商品一级类目为0,发布成功，根据二级类目补齐");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setFirstCategoryId(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_010() {
		Logger.start(true,"参数校验-编辑微店商品，规格缺失,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setCatalogList(null);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_011() {
		Logger.start(true,"参数校验-编辑微店商品，商品数据缺失,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.setProduct(null);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_012() {
		Logger.start(true,"参数校验-编辑微店商品，主图重复,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			List<String> picUrls = new ArrayList<>();
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			microproductBean.getProduct().setPicUrls(picUrls);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_013() {
		Logger.start(true,"参数校验-编辑微店商品，商品名称含有不宜发布的特殊字符“\\”,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setProductName("你好“\\”");
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_014() {
		Logger.start(true,"参数校验-编辑微店商品，无效的商品图片,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setPicUrls(null);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_015() {
		Logger.start(true,"参数校验-编辑微店商品，商品图片无http,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			List<String> picUrls = new ArrayList<>();
			picUrls.add("//pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			microproductBean.getProduct().setPicUrls(picUrls);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_016() {
		Logger.start(true,"参数校验-编辑微店商品，启用规格价格小于等于0,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getCatalogList().get(0).setPrice(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");
			microproductBean.getProduct().getCatalogList().get(0).setPrice(-1);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_017() {
		Logger.start(true,"参数校验-编辑微店商品，启用规格库存小于等于0,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getCatalogList().get(0).setStock(0);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");
			microproductBean.getProduct().getCatalogList().get(0).setStock(-1);
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("400",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_018() {
		Logger.start(true,"敏感词校验-商品名称,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setProductName("全网唯一");
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_019() {
		Logger.start(true,"敏感词校验-规格名称,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getCatalogList().get(0).setCatalogName("全网唯一");
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MicroProduct_020() {
		Logger.start(true,"敏感词校验-文描文字,发布失败");
		try {
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().getProductDescModel().setDescription("全网唯一");
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("201",microproductCall.getString("Code"),"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_MicroProduct_021() {
		Logger.start(true,"微店商品进入直播");
		try {
			List<Integer> liveIds = LiveCallService.createLivesInProcessAndInFuture(sellerId, sellerName, 2, 3);
			AddMicroProductBean microProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String productId = ProductManagerCallServiceV3.Addmicroproduct(microProductBean);
			microproductBean = ProductManagerCallServiceV3.getMicroproductBean(productId,microProductBean);
			microproductBean.getProduct().setLiveId(liveIds.get(0));
			microproductCall.setData(microproductBean);
			microproductCall.callService();
			Logger.verifyEquals("200",microproductCall.getString("Code"),"验证Code");
			AddProductCallServiceV2.checkMicroProduct(productId,microproductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}